package com.example.qxapp;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.example.qxapp.Fragment.Fragment1;
import com.example.qxapp.Fragment.Fragment2;
import com.example.qxapp.Fragment.Fragment3;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    //private TextView snickname;
   private LinearLayout tab1,tab2,tab3;
   private Fragment tabsy,tabfx,tabmy;
   private ImageView img1,img2,img3;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

       //snickname=findViewById(R.id.snickname);
        //snickname.setText("");
//        BmobUser user=BmobUser.getCurrentUser(User.class);
//        String id=user.getObjectId();
//        BmobQuery<User> myuser=new BmobQuery<User>();
//        myuser.getObject(id, new QueryListener<User>() {
//            @Override
//            public void done(User user, BmobException e) {
//                if (e==null){
//                    snickname.setText(user.getNickname());
//                }
//            }
//        });
        initview();
        tab1.setOnClickListener(this);
        tab2.setOnClickListener(this);
        tab3.setOnClickListener(this);
        ssy();

    }

    private void ssy() {
        img1.setImageResource(R.drawable.homepage_fill);
        img2.setImageResource(R.drawable.mobilephone);
        img3.setImageResource(R.drawable.mine);


        tabsy=new Fragment1();
        FragmentManager fm1=getSupportFragmentManager();
        FragmentTransaction transaction1=fm1.beginTransaction();
        transaction1.replace(R.id.fm,tabsy);
        transaction1.commit();
    }

    void initview(){
        tab1=findViewById(R.id.tab1);
        tab2=findViewById(R.id.tab2);
        tab3=findViewById(R.id.tab3);
        img1=findViewById(R.id.img1);
        img2=findViewById(R.id.img2);
        img3=findViewById(R.id.img3);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tab1:
                ssy();
                break;
            case R.id.tab2:
                img1.setImageResource(R.drawable.homepage);
                img2.setImageResource(R.drawable.mobilephone_fill);
                img3.setImageResource(R.drawable.mine);
                tabfx=new Fragment2();
                FragmentManager fm2=getSupportFragmentManager();
                FragmentTransaction transaction2=fm2.beginTransaction();
                transaction2.replace(R.id.fm,tabfx);
                transaction2.commit();
                break;
            case R.id.tab3:
                img1.setImageResource(R.drawable.homepage);
                img2.setImageResource(R.drawable.mobilephone);
                img3.setImageResource(R.drawable.mine_fill);
                tabmy=new Fragment3();
                FragmentManager fm3=getSupportFragmentManager();
                FragmentTransaction transaction3=fm3.beginTransaction();
                transaction3.replace(R.id.fm,tabmy);
                transaction3.commit();
                break;
        }
    }
}
